<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>健康管理</title>
    <meta name="description" content="健康管理">
    <meta name="keywords" content="健康管理">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
    </style>


</head>


<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统管理<small>菜单管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统管理</el-breadcrumb-item>
            <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">


                <el-input placeholder="角色名称/角色关键字" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="pagination.currentPage = 1; findPage()" class="dalfBut">查询</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>


                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="角色名称" align="center"></el-table-column>
                <el-table-column prop="keyword" label="角色关键字" align="center"></el-table-column>
                <el-table-column prop="description" label="角色描述" align="center"></el-table-column>


                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑该角色可见菜单</el-button>
                    </template>
                </el-table-column>
            </el-table>


            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑角色" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">

                                <el-form ref="dataEditForm" :model="formData" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="角色名称" prop="name">
                                                <el-input v-model="formData.name" :disabled="true"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="角色关键字" prop="keyword">
                                                <el-input v-model="formData.keyword" :disabled="true"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="角色描述">
                                                <el-input v-model="formData.description" type="textarea"
                                                          :disabled="true"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                                <div slot="footer" class="dialog-footer">
                                    <el-button @click="dialogFormVisible = false">取消</el-button>
                                    <el-button type="primary" @click="handleAdd()">确定</el-button>
                                </div>

                            </el-tab-pane>

                            <el-tab-pane label="角色可见菜单信息"  name="aa">
                                <el-tree
                                        :data="tree"
                                        show-checkbox
                                        node-key="id"

                                        default-expand-all
                                        :default-checked-keys="checkedKeys"
                                        ref="tree"
                                >
                                </el-tree>
                            </el-tab-pane>

                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>

                </el-dialog>
            </div>
        </div>
    </div>


</div>


</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>


<script>

    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            tree: [
                {
                    id: 1,
                    label: '会员管理',
                    children: [{
                        id: 2,
                        label: '会员档案',
                        children: []
                    }, {
                        id: 3,
                        label: '体检上传',
                        children: []
                    }, {
                        id: 4,
                        label: '会员统计',
                        children: []
                    },
                    ]
                },
                {
                    id: 5,
                    label: '预约管理',
                    children: [{
                        id: 6,
                        label: '预约列表'
                    }, {
                        id: 7,
                        label: '预约设置'
                    }, {
                        id: 8,
                        label: '套餐管理'
                    }, {
                        id: 9,
                        label: '检查组管理'
                    }, {
                        id: 10,
                        label: '检查项管理'
                    }]
                },
                {
                    id: 11,
                    label: '健康评估',
                    children: [{
                        id: 12,
                        label: '中医体质辨识'
                    }]
                },
                {
                    id: 13,
                    label: '统计分析',
                    children: [{
                        id: 14,
                        label: '会员数量'
                    }, {
                        id: 20,
                        label: '套餐占比'
                    }, {
                        id: 21,
                        label: '运营数据'
                    }]
                },
                {
                    id: 15,
                    label: '系统设置',
                    children: [{
                        id: 16,
                        label: '菜单管理'
                    }, {
                        id: 17,
                        label: '用户管理'
                    }, {
                        id: 18,
                        label: '角色管理'
                    }, {
                        id: 19,
                        label: '权限管理'
                    }]
                },
                {
                    id: 22,
                    label: '工作台',
                    children: [{
                        id: 23,
                        label: '地址管理'
                    },
                        {
                            id:24,
                            label: '行为日志'
                        }]
                }
            ],
            checkedKeys: [], //默认勾选的菜单
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            permissionIds: [],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
        },

        created() { //钩子函数 页面加载完毕自动执行
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
                // 全选 getCheckedKeys()
                // 半选 getHalfCheckedKeys()
                let ids = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys())

                axios.post("/menu/updateById.do?ids=" + ids, this.formData).then((response) => {
                    this.dialogFormVisible4Edit = false;
                    if (response.data.flag) {
                        this.$message.success(response.data.message)
                    } else {
                        this.$message.error(response.data.message)
                    }
                })

            },


            //分页查询 使用了钩子函数 页面加载完毕后自动执行一次
            findPage() {
                //定义数据，查询数据库
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                }
                //发送ajax请求
                axios.post("/role/findPage.do", param).then((response) => {
                    //响应回来的数据
                    this.pagination.total = response.data.total //总条数
                    this.dataList = response.data.rows //遍历的数据
                })
            },

            // 重置表单
            resetForm() {
                this.formData = {};

            },


            //弹出编辑窗口
            handleUpdate(row) { //这个row有这一行的所有的数据

                this.formData = row;
                this.activeName = 'first';
                this.permissionIds = [];
                this.dialogFormVisible4Edit = true;
                // 查询数据库，查询出编辑的这个权限的详细信息用于展示
                //获取菜单信息
                axios.get("/menu/findById.do?id=" + row.id).then((response) => {
                    if (response.data.flag) {
                        this.$refs.tree.setCheckedKeys([]);
                        this.checkedKeys = response.data.data;
                    }
                })
            },


            //切换页码 参数 currentPage 是切换后的页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            //权限不足框架抛出的异常信息
            showMessage(r) {
                if (r == "Error: Request failed with status code 403") {
                    //权限不足 ? ?
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            }


        }

    })

</script>
</html>
